﻿$(function () {

    $("#EnterpriseId").change(function () {
        var id = $(this).children("option:selected").attr("id");
        if(id!=undefined){
            $.MGJ.RawCode.Ajax_GetBatch(id);
            $.L.ajaxHandle({
                url: ACTION_URL("Getproductlist", "CodeManage") + "?Eid=" + id,
                success: function (response) {
                var $option = response.length == 0 ? "<option value='0'  selected>请先添加产品名称</option>" : "<option value='0' selected >--请选择--</option>";
                    $(response).each(function (i, e) {
                        $option += " <option value='" + e.Code + "'>" + e.Name + "</option>";
                    });
                    $("#ProductId").html($option);
                }
            })
        } else {
            $("#Batch").val("");
            $('#form_BornCode').data('bootstrapValidator')
                .updateStatus('Batch', 'NOT_VALIDATED', null)
                .validateField('Batch');
        }
    });
    $("#ProductId").change(function (id) {
        var id = $("#ProductId").val();
        $.L.ajaxHandle({
            url: ACTION_URL("GetTypehlist", "CodeManage") + "?Pid=" + id,
            success: function (response) {
                var $option = response.length == 0 ? "<option value='0' selected >请先添加类型名称</option>" : "<option value='0' selected >--请选择--</option>";
                $(response).each(function (i, e) {
                    $option += " <option value='" + e.Id + "'>" + e.TypeName + "</option>";
                });
                $("#TypeId").html($option);
            }
        })
    });
    $("#ProductId").change(function (id) {
        var id = $("#ProductId").val();
        $.L.ajaxHandle({
            url: ACTION_URL("GetBatchlist", "CodeManage") + "?Pid=" + id,
            success: function (response) {
                var $option = response.length == 0 ? "<option value='0' selected >请先添加批次名称</option>" : "<option value='0' selected >--请选择--</option>";
                $(response).each(function (i, e) {
                    $option += " <option value='" + e.Id + "'>" + e.BatchName + "</option>";
                });
                $("#ProductBatchId").html($option);
            }
        })
    });
  

})
